<?php
function cutText($string, $length, $encoding='utf-8', $end='...') {
    if(mb_strlen($string, $encoding) >= $length) {
        return mb_substr($string, 0, $length, $encoding).$end;
    } else {
        return $string;
    }
}

//信息列表详细内容展开与收回专用
function cutText2($string, $length, $encoding='utf-8', $end='...', $end2 = '<span style="display:none;"></span>') {
    if(mb_strlen($string, $encoding) >= $length) {
        return mb_substr($string, 0, $length, $encoding).$end;
    } else {
        return $string.$end2;
    }
}

function jump($url) {
    header('Location:'.$url);
}

function len($string, $encoding='utf-8') {
    return mb_strlen($string, $encoding);
}

function createDate() {
    return date('Y-m-d H:i:s');
}

function getIp() {
    return $_SERVER['REMOTE_ADDR'];
}

function alertAndClose($info, $value, $formName, $input) {
    echo <<<END
        <script type='text/javascript'>
            alert('$info');
            var a = opener.document.$formName;
            a.$input.value='$value';
            window.close();
        </script>
END;
}

function isEnglish($string) {
    return preg_match('/^[a-zA-Z]+$/', $string) === 1 ? true : false;
}

//获取配置信息
function getSetting($set = '') {
    $setting = simplexml_load_file('Conf/setting.xml');
    return !empty($set) ? $setting->$set : $setting;
}
?>